/**
 * 断言
 * 
 */
class Assertions {

    /**
     * 响应断言
     * 
     * @param {XMLBuilder} parent 
     * @param {{testname: string, subString: string}} config
     * @returns
     */
    createResponseAssertion(parent, config = { testname: "Response Assertion", subString: "" }) {
        const { testname, subString } = config;
        const jmxResponseAssertion = parent.ele("ResponseAssertion", {
            guiclass: "AssertionGui",
            testclass: "ResponseAssertion",
            testname: testname
        });
        jmxResponseAssertion.ele("collectionProp", { name: "Asserion.test_strings" })
            .ele("stringProp", { name: "-1867169789" }).txt(subString).up().up()
            .ele("stringProp", { name: "Assertion.custom_message" }).txt("").up()
            .ele("stringProp", { name: "Assertion.test_field" }).txt("Assertion.response_data").up()
            .ele("boolProp", { name: "Assertion.assume_success" }).txt("false").up()
            .ele("intProp", { name: "Assertion.test_type" }).txt("16");
        jmxResponseAssertion.up().ele("hashTree");
    }

    /**
     * JSR223断言
     * 
     * @param {XMLBuilder} parent 
     * @param {{testname: string, subString: string}} config
     * @returns
     */
    createJsr223Assertion(parent, config = { testname: "JSR223 Assertion", script: "" }) {
        const { testname, script } = config;
        const jmxJsr223Assertion = parent.ele("JSR223Assertion", {
            guiclass: "TestBeanGUI",
            testclass: "JSR223Assertion",
            testname: testname
        });
        jmxJsr223Assertion.ele("stringProp", { name: "cacheKey" }).txt("true").up()
            .ele("stringProp", { name: "filename" }).txt("").up()
            .ele("stringProp", { name: "parameters" }).txt("").up()
            .ele("stringProp", { name: "script" }).txt(script).up()
            .ele("stringProp", { name: "scriptLanguage" }).txt("groovy");
        jmxJsr223Assertion.up().ele("hashTree");
    }

}

module.exports = Assertions;